package com.shell.arouter.demo.room

import com.alibaba.android.arouter.facade.annotation.Route
import com.durian.base.frame.easyrouter.EasyRouter
import com.henanjianye.soon.communityo2o2.R
import com.shell.arouter.demo.IHomeAction
import com.shell.arouter.extend.PATH_ROOM
import com.shell.arouter.ui.FragmentCommon

/**
 * 说明：ActionRoom
 * <p/>
 * 作者：fanly
 * <p/>
 * 类型：Class
 * <p/>
 * 时间：2019-12-20 11:55
 * <p/>
 * 版本：version 1.0
 */
class ActionRoom : IHomeAction {
    override fun todo() {
        EasyRouter.buildByFragment(PATH_ROOM).navigation()
    }

    override fun name(): String {
        return "Room"
    }
}

//class RoomViewModels(application: Application) : AndroidViewModel(application) {
//    val db by lazy {
//        Room.databaseBuilder(application, AppDatabase::class.java, "room_db").build()
//    }
//    val adapter by lazy {
//        val adapter = MultiTypeAdapter<Any>()
//        adapter.register(RoomUser::class.java, RoomItemPrivider().setOnItemClickListener { position, item ->
//            viewModelScope.launch(Dispatchers.IO) {
//                db.userDao().delete(item)
//                ("删除成功").toast()
//            }
//        })
//        adapter
//    }
//
//    init {
//        viewModelScope.launch(Dispatchers.IO) {
//            //            db.clearAllTables()
//        }
//    }
//
//    fun insertAllUsers(list: MutableList<RoomUser>) {
//        viewModelScope.launch {
//            launch((Dispatchers.IO)) {
//                db.userDao().insertRoomUser(*(list.toTypedArray()))
//            }
//            ("添加成功").toast()
//        }
//    }
//}
//
//
//class RoomItemPrivider : ItemViewProvider<RoomUser>() {
//    override fun convert(holder: MultiItemViewHolder, item: RoomUser, position: Int) {
//        if (holder.mItemView is TextView) {
//            (holder.mItemView as TextView).text = item.toString()
//        }
//    }
//
//    override fun getItemLayoutId(): Int {
//        return 0
//    }
//
//    override fun getItemView(context: Context?): View {
//        return TextView(context)
//    }
//
//}

@Route(path = PATH_ROOM)
class FragmentRoom : FragmentCommon() {

//    val viewModel: RoomViewModels by viewModels()

    override fun onFirstUserVisible() {
        super.onFirstUserVisible()
//        rvItems.adapter = viewModel.adapter
//        btnInsert.setOnClickListener { btnInsert() }
//        btnQuery.setOnClickListener { findData() }
    }

    override fun isShowTitleBar(): Boolean {
        return true
    }

    override fun getRootViewResID(): Int {
        return R.layout.fragment_room
    }

    override fun bindTitleBarText(): String {
        return "Room"
    }

//    fun btnInsert() {
//        val users = arrayListOf<RoomUser>()
//        (1..10).forEach {
//            users.add(RoomUser(0, "firstName-$it", FileUtils.readFileFromAssets(activity,"demo-room.txt")))
//        }
//        viewModel.insertAllUsers(users)
//    }
//
//    fun findData() {
//
//    }

}